package cn.school.teacher.leaveCount.service.impl;

import cn.school.teacher.leaveCount.dao.DeptLeaveDao;
import cn.school.teacher.leaveCount.entity.DeptLeave;
import cn.school.teacher.leaveCount.service.DeptLeaveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("DeptLeaveService")
public class DeptLeaveServiceImpl implements DeptLeaveService {

    @Resource
    DeptLeaveDao deptLeaveDao;

    @Override
    public PageInfo selectLeaveList(Map<String, Object> params) {
        int pageNum = Integer.parseInt(String.valueOf(params.get("pageNum")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("pageSize")));
        String time = params.get("time").toString();
        PageHelper.startPage(pageNum,pageSize);
        Integer status = 3;
        List<DeptLeave> deptLeaves = deptLeaveDao.leaveList(status, time);
        for(int i=0;i<deptLeaves.size();i++){
            String name = deptLeaves.get(i).getDeptName();
            int leaveCount = deptLeaveDao.leaveCount(status, time, name);
            deptLeaves.get(i).setLeaveCount(leaveCount);
        }
        PageInfo page = new PageInfo(deptLeaves);
        return page;
    }
}
